<template>
  <div class="region">
    <div class="content">
      <div class="left">地区:</div>
      <ul>
        <li :class="{active:regionFlag == ''}"
             @click="changeRegion('')">
          全部
        </li>
        <li v-for="item in regionArr"
            :key="item.value"
            @click="changeRegion(item.value)"
            :class="{active:regionFlag == item.value}">
          {{ item.name }}
        </li>
      </ul>
    </div>
  </div>
</template>
<script setup lang="ts">
import { onMounted,ref } from 'vue';
import { reqHospitalLevelAndRegion } from "@/api/home";
import type { HospitalLevelAndRegionResponseData, HospitalLevelAndRegionArr } from "@/api/home/type";
let regionArr = ref<HospitalLevelAndRegionArr>([]);
let regionFlag = ref<string>('');
onMounted(() => {
  getRegion();
})
const getRegion = async () => {
  let result:HospitalLevelAndRegionResponseData = await reqHospitalLevelAndRegion('Beijin');
  //存储医院地区数据
  if(result.code == 200) {
    regionArr.value = result.data;
  }
}
const changeRegion = (region:string) => {
  //高亮的响应式数据存储 level 数值
  regionFlag.value = region


  //触发自定义事件：将医院等级参数回传给父组件
  $emit('getRegion', region);
}
let $emit = defineEmits(['getRegion'])
</script>
<style scoped lang="scss">
.region {
  color: #7f7f7f;
  margin-top: 10px;

  .content {
    display: flex;
    .left {
      margin-right: 10px;
      width: 50px;
    }

    ul {
      display:flex;
      flex-wrap:wrap;
      li {
        margin-bottom: 10px;
        margin-right: 10px;

        &.active {
          color: #55a6fe;
        }
      }
      li:hover {
        color: #55a6fe;
        cursor: pointer;
      }
    }
  }
}
</style>
